<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>

<head>
	<style>
		.directionstyle .rightclose{
			display: block !important;
		}
	</style>
	<title>方向资源管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        var imgflag=true;
        var imgflag1=true;
		$(document).ready(function() {
		    $(".directionstyle .direunshow").css("display","none");
            $(".removestyle *").removeClass("updownbg");
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
                    var rows1 = $('#eleSourceDirectionUpList').children('div').length;
                    var rows2 = $('#eleSourceDirectionDownList').children('div').length;
                    if((rows1+rows2)!=0) {
                        $("#eleSourceDirectionUpList>div").each(function () {
                            imgflag = true;
                            var reg = /\d+/g;
                            var str = this.id;
                            var i = str.match(reg)
                            var image = $("#direction_" + i).val();
                            if (document.getElementById("eleSourceDirectionUpList" + i).className != "error") {
                                if (image == null || image == "") {
                                    alertx("<spring:message code='tip.chooseimg'/>");
                                    imgflag = false;
                                    return false;
                                }
                            }
                        }),
                        $("#eleSourceDirectionDownList>div").each(function () {
                                imgflag1 = true;
                                var reg = /\d+/g;
                                var str = this.id;
                                var i = str.match(reg)
                                var image = $("#direction_" + i).val();
                                if (document.getElementById("eleSourceDirectionList" + i).className != "error") {
                                    if (image == null || image == "") {
                                        alertx("<spring:message code='tip.chooseimg'/>");
                                        imgflag1 = false;
                                        return false;
                                    }
                                }
                            })

                    }
                    if(imgflag&&imgflag1){
                        loading('<spring:message code="common.subbmiting"/>');
                        timeVali($("#btnSubmit"));
                        form.submit();
					}


				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row,remarks:idx,
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
        function addRow2(list, idx, tpl, row){
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row,remarks:idx,
            }));
            $(list+idx).find("select").each(function(){
                $(this).val($(this).attr("data-value"));
            });
            $(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
                var ss = $(this).attr("data-value").split(',');
                for (var i=0; i<ss.length; i++){
                    if($(this).val() == ss[i]){
                        $(this).attr("checked","checked");
                    }
                }
            });
        }
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().addClass("error");
                $(obj).parent().css("display","none");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "<spring:message code='common.delete'/>");
				$(obj).parent().removeClass("error");
			}
		}
	</script>

	<style>
		.directionstyle{
			float: left;
			width: 25%;
		}
		.updownbg{
			position: relative;
			display: inline-block;
			background-color: #f1f1f1;
			border: 1px solid #B5B5B5;
			border: 1px solid #B5B5B5;
			height: 86px;
			vertical-align: middle;
			text-align: center;
			width: 86px;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/source/direction/eleSourceDirectionGroup/">
			<spring:message code="direction.list"/>
		</a></li>
		<li class="active">
			<a href="${ctx}/source/direction/eleSourceDirectionGroup/form?id=${eleSourceDirectionGroup.id}">
				<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit">
					<c:if test="${not empty eleSourceDirectionGroup.id}">
						<spring:message code="direction.modify"/>
					</c:if>
					<c:if test="${empty eleSourceDirectionGroup.id}">
						<spring:message code="direction.add"/>
					</c:if>
				</shiro:hasPermission>
				<shiro:lacksPermission name="source:direction:eleSourceDirectionGroup:edit">
					<spring:message code="direction.info"/>
				</shiro:lacksPermission>
			</a>
		</li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="eleSourceDirectionGroup" action="${ctx}/source/direction/eleSourceDirectionGroup/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.dname"/>：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="25" class="input-xlarge required"/>
											<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group directionstyle">
			<label class="control-label"><spring:message code="direction.static.image"/>：</label>
			<div class="controls ">
				<form:hidden id="stop" path="stop" htmlEscape="false" maxlength="255" class="input-small"/>
				<sys:ckfinder2 input="stop" type="images" uploadPath="/source/direction" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>
		<div class="control-group directionstyle" >
			<label class="control-label"><spring:message code="direction.upside.image"/>：</label>
			<div class="controls">
				<form:hidden id="upstop" path="upstop" htmlEscape="false" maxlength="255" class="input-small"/>
				<sys:ckfinder2 input="upstop" type="images" uploadPath="/source/direction" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>

		<div class="control-group directionstyle" >
			<label class="control-label"><spring:message code="direction.down.image"/>：</label>
			<div class="controls">
				<form:hidden id="downstop" path="downstop" htmlEscape="false" maxlength="255" class="input-small"/>
				<sys:ckfinder2 input="downstop" type="images" uploadPath="/source/direction" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>
		<div class="control-group directionstyle" >
			<label class="control-label"><spring:message code="direction.doublestop.image"/>：</label>
			<div class="controls">
				<form:hidden id="doublestop" path="doublestop" htmlEscape="false" maxlength="255" class="input-small"/>
				<sys:ckfinder2 input="doublestop" type="images" uploadPath="/source/direction" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>
		<div class="control-group  removestyle" style="width: 50%;float: left;clear: left">
			<label class="control-label"><spring:message code="direction.upside.tone"/>：</label>
			<div class="controls">
				<form:hidden id="uptips" path="uptips" htmlEscape="false" maxlength="255" class="input-small"/>
				<sys:ckfinder2 input="uptips" type="audios" uploadPath="/source/direction" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>
		<div class="control-group  removestyle"  style="width: 50%;float: left;clear: right">
			<label class="control-label"><spring:message code="direction.down.tone"/>：</label>
			<div class="controls">
				<form:hidden id="downtips" path="downtips" htmlEscape="false" maxlength="255" class="input-small"/>
				<sys:ckfinder2 input="downtips" type="audios" uploadPath="/source/direction" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>
<%--		<div class="control-group">
			<label class="control-label"><spring:message code="direction.default.tone"/>：</label>
			<div class="controls">
				<form:hidden id="deftips" path="deftips" htmlEscape="false" maxlength="255" class="input-small"/>
				<sys:ckfinder input="deftips" type="audios" uploadPath="/source/direction" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>--%>

			<div class="control-group" style="clear: both">
				<label class="control-label"><spring:message code="direction.node"/>：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th style="width: 100px"><spring:message code="direction.arrow"/></th>
								<th><spring:message code="direction.status.unit"/></th>
								<%--<th><spring:message code='common.remarks'/></th>--%>
								<%--<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit"><th width="10">&nbsp;</th></shiro:hasPermission>--%>
							</tr>
						<tr>
							<td><div  style="text-align: center"><spring:message code="direction.up"/></div>
								<div>
									<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit">
										<a href="javascript:" onclick="addRow('#eleSourceDirectionUpList', eleSourceDirectionRowIdx, eleSourceDirectionUpTpl);eleSourceDirectionRowIdx = eleSourceDirectionRowIdx + 1;" class="btn"><spring:message code="common.add"/></a>
									</shiro:hasPermission>
								</div>

							</td>
							<td id="eleSourceDirectionUpList"></td>
						</tr>
							<tr>
								<td>
									<div style="text-align: center"><spring:message code="direction.down"/></div>
									<div>
										<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit">
											<a href="javascript:" onclick="addRow2('#eleSourceDirectionDownList', eleSourceDirectionRowIdx, eleSourceDirectionDownTpl);eleSourceDirectionRowIdx = eleSourceDirectionRowIdx + 1;" class="btn"><spring:message code="common.add"/></a>
										</shiro:hasPermission>
									</div>

								</td>
								<td id="eleSourceDirectionDownList"></td>
							</tr>
						</thead>
						<%--<tbody id="eleSourceDirectionList">
						</tbody>--%>

					</table>
					<script type="text/template" id="eleSourceDirectionUpTpl">//<!--
					<div id="eleSourceDirectionUpList{{idx}}" style="float:left;margin-right:20px;">
					<td class="hide" >
								<input id="eleSourceDirectionList{{idx}}_id" name="eleSourceDirectionList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="eleSourceDirectionList{{idx}}_remarks" name="eleSourceDirectionList[{{idx}}].remarks" type="hidden" value="{{remarks}}"/>
								<input id="eleSourceDirectionList{{idx}}_delFlag" name="eleSourceDirectionList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td  class="hide" >
								<select style="display:none" id="eleSourceDirectionList{{idx}}_direction" name="eleSourceDirectionList[{{idx}}].direction" data-value="{{row.direction}}" class="input-small ">
										<option value="up" selected="selected">Up</option>
								<%--	<c:forEach items="${fns:getDictList('direction')}" var="dict">
										<option value="${dict.value}">${dict.label}</option>
									</c:forEach>--%>
								</select>
							</td>
							<td>
								<input type="hidden" id="direction_{{idx}}" name="eleSourceDirectionList[{{idx}}].node" type="text" value="{{row.node}}" maxlength="255" class="input-small "/>
								<sys:ckfinder2 input="direction_{{idx}}" type="images" uploadPath="/source/direction" selectMultiple="false"/>
							</td>

							<%--<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceDirectionList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>--%>
					</div>

					//-->
					</script>

					<script type="text/template" id="eleSourceDirectionDownTpl">//<!--
					<div id="eleSourceDirectionList{{idx}}" style="float:left;margin-right:20px;">
					<td class="hide">
								<input id="eleSourceDirectionList{{idx}}_id" name="eleSourceDirectionList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="eleSourceDirectionList{{idx}}_remarks" name="eleSourceDirectionList[{{idx}}].remarks" type="hidden" value="{{remarks}}"/>
								<input id="eleSourceDirectionList{{idx}}_delFlag" name="eleSourceDirectionList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td  class="hide">
								<select style="display:none" id="eleSourceDirectionList{{idx}}_direction" name="eleSourceDirectionList[{{idx}}].direction" data-value="{{row.direction}}" class="input-small ">
										<option value="down" selected="selected">Down</option>
								<%--	<c:forEach items="${fns:getDictList('direction')}" var="dict">
										<option value="${dict.value}">${dict.label}</option>
									</c:forEach>--%>
								</select>
							</td>
							<td>
								<input type="hidden" id="direction_{{idx}}" name="eleSourceDirectionList[{{idx}}].node" type="text" value="{{row.node}}" maxlength="255" class="input-small "/>
								<sys:ckfinder2 input="direction_{{idx}}" type="images" uploadPath="/source/direction" selectMultiple="false"/>
							</td>
							<%--<td>
								<textarea id="eleSourceDirectionList{{idx}}_remarks" name="eleSourceDirectionList[{{idx}}].remarks" rows="2" maxlength="255" class="input-small ">{{row.remarks}}</textarea>
							</td>--%>
							<%--<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceDirectionList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>--%>
					</div>

					//-->
					</script>
					<script type="text/template" id="eleSourceDirectionTpl">//<!--
						<tr id="eleSourceDirectionList{{idx}}">
							<td class="hide">
								<input id="eleSourceDirectionList{{idx}}_id" name="eleSourceDirectionList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="eleSourceDirectionList{{idx}}_delFlag" name="eleSourceDirectionList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<select id="eleSourceDirectionList{{idx}}_direction" name="eleSourceDirectionList[{{idx}}].direction" data-value="{{row.direction}}" class="input-small ">
									<option value="up" selected="selected"></option>
									<%--<c:forEach items="${fns:getDictList('direction')}" var="dict">
										<option value="${dict.value}">${dict.label}</option>
									</c:forEach>--%>
								</select>
							</td>
							<td>
								<input type="hidden" id="direction_{{idx}}" name="eleSourceDirectionList[{{idx}}].node" type="text" value="{{row.node}}" maxlength="255" class="input-small "/>
								<sys:ckfinder2 input="direction_{{idx}}" type="images" uploadPath="/source/direction" selectMultiple="false"/>
							</td>
							<%--<td>
								<textarea id="eleSourceDirectionList{{idx}}_remarks" name="eleSourceDirectionList[{{idx}}].remarks" rows="2" maxlength="255" class="input-small ">{{row.remarks}}</textarea>
							</td>--%>
						<%--	<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceDirectionList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>--%>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var eleSourceDirectionRowIdx = 0, eleSourceDirectionUpTpl = $("#eleSourceDirectionUpTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,""),eleSourceDirectionDownTpl = $("#eleSourceDirectionDownTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceDirectionGroup.uplist)};
                            var data2 = ${fns:toJson(eleSourceDirectionGroup.downlist)};
							for (var i=0; i<data.length; i++) {
                                addRow('#eleSourceDirectionUpList', eleSourceDirectionRowIdx++, eleSourceDirectionUpTpl, data[i]);
      //                          eleSourceDirectionRowIdx = eleSourceDirectionRowIdx + 1;
                            }
                            for (var i=0; i<data2.length; i++) {
                                addRow2('#eleSourceDirectionDownList', eleSourceDirectionRowIdx++, eleSourceDirectionDownTpl, data2[i]);
//								eleSourceDirectionRowIdx = eleSourceDirectionRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>


		<div class="control-group" style="clear: both">
			<label class="control-label"><spring:message code='common.remarks'/>：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="2" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="source:direction:eleSourceDirectionGroup:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.save'/>"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="<spring:message code='common.back'/>" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>